package com.vivi.feverdiagnose;

import com.vivi.feverdiagnose.json.JSONParser;
import com.vivi.feverdiagnose.R;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;

public class MainLoadData extends MainMenu{
ProgressDialog mProgressDialog;
	
	/** Called when the activity is first created. */	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.splash);
		
		new DownloadJSON().execute();
		
	}
	
	private class DownloadJSON extends AsyncTask<Void, Void, Void> {
		@Override
		protected void onPreExecute() {
			super.onPreExecute();
			// Create a progressdialog
			mProgressDialog = new ProgressDialog(MainLoadData.this);
			// Set progressdialog title
			mProgressDialog.setTitle("Download Data");
			// Set progressdialog message
			mProgressDialog.setMessage("Loading...");
			mProgressDialog.setIndeterminate(false);
			// Show progressdialog
			mProgressDialog.show();
		}

		@Override
		protected Void doInBackground(Void... params) {
			JSONParser j = new JSONParser();
			j.JSONtoDBGejala(MainLoadData.this, false);
			j.JSONtoDBPenyakit(MainLoadData.this, false);
			//j.JSONtoDBRole(MainLoadData.this, false);
			return null;
		}
		
		@Override
		protected void onPostExecute(Void args) {
			Intent intent = new Intent(getApplicationContext(), MainMenu.class);
			intent.setFlags (Intent.FLAG_ACTIVITY_CLEAR_TOP);
	    	startActivity(intent);
			// Close the progressdialog
			mProgressDialog.dismiss();
		}

	}

}
